package com.cjh.scala

/**
 * Created by Administrator on 2016/6/10 0010.
 */
class Basic3 {

}

abstract class animal{
  def speak
}

class Person5() extends  animal with  Logger{
  override def speak: Unit ={
    println("i can speak!!!")
  }
}
class  Person6(){
  def speak: Unit ={
    println("i can speak!!!")
  }
}
//特质trait是字段和行为的集合 可以当成能够带有实现方法的接口
//第一个trait用extends 后面的trait用with累加
//覆盖抽象方法不加override
trait  Logger{
  def log(msg:String){
    println("log "+msg)
  }
}
trait Log{
  def log
}

//特质可以继承 子特质可以重写父特质的方法
trait ConsoleLog extends  Log{
  def speak(msg:String){
    println("log "+msg)
  }
}

trait  TextLogger extends  Logger{
  override def log(msg:String): Unit ={
    println("TextLogger")
  }
}


object  Basic3 extends  App{
//  val p=new Person5
//  p.speak
//  p.log("hahaha")
   val p=new Person6 with  Logger //在对象中混入特质，前面是在类中混入特质
  p.log("hahaha")
}